package models

import (
	"gorm.io/gorm"
	"server/basic/config"
	"time"
)

type Collect struct {
	Id         uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId     uint           `gorm:"column:user_id;type:bigint UNSIGNED;comment:用户id;not null;default:0;" json:"user_id"`      // 用户id
	GoodsId    uint           `gorm:"column:goods_id;type:bigint;comment:商品id;not null;" json:"goods_id"`                       // 商品id
	GoodsPrice uint           `gorm:"column:goods_price;type:int UNSIGNED;comment:商品价格;not null;default:0;" json:"goods_price"` // 商品价格
	GoodsImage string         `gorm:"column:goods_image;type:varchar(255);comment:商品图片;not null;" json:"goods_image"`           // 商品图片
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Collect) TableName() string {
	return "collect"
}
func (c *Collect) CreateCollect() error {
	return config.DB.Create(&c).Error
}
func (c *Collect) DeleteCollect() error {
	return config.DB.Where("id = ?", c.Id).Delete(&c).Error
}
